<?php
class ExtLb_Controller_Helper_Acl {
	public   $acl;
	
	public function __construct(){
		$this->acl = new Zend_Acl();
		
		$this->setRoles();
		$this->setResources();
		$this->setPrivilages();
		$this->setAcl();
	}
	
	private  function setRoles(){
		$this->acl->addRole(new Zend_Acl_Role('admin'));
		$this->acl->addRole(new Zend_Acl_Role('giaovien'));
		$this->acl->addRole(new Zend_Acl_Role('sinhvien'));
		$this->acl->addRole(new Zend_Acl_Role('guest'));
	}
	
	private  function setResources(){
		//
		//PHAN QUYEN THEO CONTROLLER
		// == CONTROLLER CUA MODULE ADMIN
		$this->acl->addResource(new Zend_Acl_Resource('comment'));
		$this->acl->addResource(new Zend_Acl_Resource('course'));
		$this->acl->addResource(new Zend_Acl_Resource('index'));
		$this->acl->addResource(new Zend_Acl_Resource('lop')); //lop is controller
		$this->acl->addResource(new Zend_Acl_Resource('mark'));		
		$this->acl->addResource(new Zend_Acl_Resource('question'));
		$this->acl->addResource(new Zend_Acl_Resource('quiz'));
		$this->acl->addResource(new Zend_Acl_Resource('student'));
		$this->acl->addResource(new Zend_Acl_Resource('tmc'));
		$this->acl->addResource(new Zend_Acl_Resource('user'));
		
		
		// == CONTROLLER CUA MODULE FRONT
		$this->acl->addResource(new Zend_Acl_Resource('exame'));
		$this->acl->addResource(new Zend_Acl_Resource('info'));
		$this->acl->addResource(new Zend_Acl_Resource('login'));	
		$this->acl->addResource(new Zend_Acl_Resource('contact'));			
	}
	
	private  function setPrivilages(){
		$this->acl->allow('guest','index','index');
		//
		// == set role for sinhvien
		$this->acl->allow('sinhvien',array('index','login','mark'),array('index'));//has access to all controller list action
		$this->acl->allow('sinhvien','exame',array('index','doexame','getexame','viewexame'));
		$this->acl->allow('sinhvien','info',array('index','edit'));
		$this->acl->allow('sinhvien','login',array('login','logout','index'));
		$this->acl->allow('sinhvien','contact');

		//
		// == SET ROLE FOR GIAOVIEN
		// == giao vien khong => them lop, xoa lop
		$this->acl->allow('giaovien',
						array('mark','question','quiz'),
						array('index','add','edit','delete')
				);
		$this->acl->allow('giaovien','quiz',array('addquestion','doexame'));
		$this->acl->allow('giaovien','question',array('inputmark','import'));
		$this->acl->allow('giaovien','user','index');
		$this->acl->allow('giaovien','lop','index');
		$this->acl->allow('giaovien','student');
		//
		//== SET ROLER FOR ADMIN
		$this->acl->allow('admin');
		
		$this->acl->deny('giaovien','user', array('add','index'));
		$this->acl->deny('giaovien','lop', array('add','edit','delete','export','import'));
	} 
	
	private function setAcl(){
		Zend_Registry::set('acl', $this->acl);
	}
	
}